package com.app.couponsharelife.ui.view

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent

import androidx.viewpager.widget.ViewPager

/**
 * Created by guluwa on 2018/12/5.
 */
class GalleryViewPager : ViewPager {

    private var isMove = false

    var listener: com.app.couponsharelife.ui.listener.OnClickListener? = null

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}

    constructor(context: Context) : super(context) {}

    override fun onTouchEvent(ev: MotionEvent): Boolean {
        when (ev.action) {
            MotionEvent.ACTION_UP -> {
                if (!isMove)
                    listener?.click(0, ev.rawX)
                else
                    isMove = false
            }
            MotionEvent.ACTION_CANCEL -> {
                isMove = false
            }
            MotionEvent.ACTION_MOVE -> {
                isMove = true
            }
        }
        return super.onTouchEvent(ev)
    }
}
